//
//  Rec.swift
//

import Alamofire

extension Network {
    enum Rec {
        /// 获取验证码
        case list
        case videos(id: String, page: Int = 1)
        case books(id: String)
        case stores(id: String, page: Int = 1)
        case audioAlbum(id: String, page: Int = 1)
        case audioList(id: String, page: Int = 1)
        case audio(pid: String, id: String)
    }
}

extension Network.Rec: TargetType {
    
    var baseURL: String {
        switch self {
        case .audioList, .audio:
            return NetworkEnvironment.audio.baseURL
        default:
            return NetworkEnvironment.rec.baseURL
        }
    }
    
    var method: HTTPMethod {
        switch self {
        case .audioList, .audio:
            return .get
        default:
            return .post
        }
    }
    
    var encoding: ParameterEncoding {
        switch self {
        case .audioList:
            return URLEncoding.default
        case .audio:
            return URLEncoding.default
        default:
            return JSONEncoding.default
        }
    }
    
    var path: String {
        switch self {
        case .list:
            return "api/v1/feature/qmtj2.json"
        case .videos:
            return "api/v1/bv/video"
        case .books:
            return "api/v1/hb/series"
        case .stores:
            return "audioapi/albumByAtrribute"
        case .audioAlbum:
            return "audioapi/albumItems"
        case .audioList:
            return "coop/api/audio/getAlbumItems"
        case .audio:
            return "coop/api/qt/getAudioRes"
        }
    }
    
    var parameters: [String: Any] {
        switch self {
        case .list:
            return ["appver": "".appVersion,
                    "userId": LoginService.default.userId,
                    "androidid": "",
                    "devicetype": 1,
                    "imei": "",
                    "channel": "c2",
                    "ua": "Mozilla/5.0",
                    "sw": 1242,
                    "osv": "14.2",
                    "srcApp": "com.ubestkid.collection",
                    "vps": "10",
                    "os": 1,
                    "sh": 2208,
                    "make": "apple",
                    "mac": "",
                    "carrier": "46002",
                    "oaid": "",
                    "ak": LoginService.default.ak,
                    "network": 1,
                    "model": "iPhone8,2",
                    "age": "1",
                    "ppi": 401,
                    "idfa": "8039a09a9a56f2cb8cbd6665251b956c2"]
        case let .videos(id, page):
            return ["appver": "".appVersion,
                    "userId": LoginService.default.userId,
                    "p": "\(page)",
                    "androidid": "",
                    "devicetype": 1,
                    "imei": "",
                    "channel": "c2",
                    "ua": "Mozilla/5.0",
                    "sw": 1242,
                    "osv": "14.2",
                    "srcApp": "com.ubestkid.collection",
                    "vps": 500,
                    "os": 1,
                    "sh": 2208,
                    "make": "apple",
                    "mac": "",
                    "carrier": "46002",
                    "oaid": "",
                    "ak": LoginService.default.ak,
                    "subcateId": id,
                    "network": 1,
                    "model": "iPhone8,2",
                    "ppi": 401,
                    "idfa": "8039a09a9a56f2cb8cbd6665251b956c2"]
        case let .books(id):
            return ["appver": "".appVersion,
                    "userId": LoginService.default.userId,
                    "seriesId": id,
                    "androidid": "",
                    "devicetype": 1,
                    "imei": "",
                    "channel": "c2",
                    "ua": "Mozilla",
                    "sw": 1242,
                    "osv": "14.2",
                    "srcApp": "com.ubestkid.collection",
                    "os": 1,
                    "sh": 2208,
                    "make": "apple",
                    "mac": "",
                    "carrier": "46002",
                    "oaid": "",
                    "ak": LoginService.default.ak,
                    "network": 1,
                    "model": "iPhone8",
                    "ppi": 401,
                    "idfa": "8039a09a9a56f2cb8cb2f51b956c2"]
        case let .stores(id, page):
            return ["appver": "".appVersion,
                    "userId": LoginService.default.userId,
                    "p": page,
                    "androidid": "",
                    "devicetype": 1,
                    "attributeId": id,
                    "imei": "",
                    "channel": "c2",
                    "ua": "Mozilla",
                    "sw": 1242,
                    "osv": "14.2",
                    "srcApp": "com.ubestkid.collection",
                    "os": 1,
                    "sh": 2208,
                    "make": "apple",
                    "mac": "",
                    "carrier": "46002",
                    "oaid": "",
                    "ak": LoginService.default.ak,
                    "network": 1,
                    "model": "iPhone8,2",
                    "ps": 30,
                    "ppi": 401,
                    "idfa": "8039a09a9a56f2cb835251b956c29"]
        case let .audioAlbum(id, page):
            return ["appver": "".appVersion,
                    "userId": LoginService.default.userId,
                    "p": page,
                    "androidid": "",
                    "devicetype": 1,
                    "imei": "",
                    "channel": "c2",
                    "ua": "Mozilla",
                    "sw": 1242,
                    "osv": "14.2",
                    "srcApp": "com.ubestkid.collection",
                    "os": 1,
                    "sh": 2208,
                    "make": "apple",
                    "albumId": id,
                    "mac": "",
                    "carrier": "46002",
                    "oaid": "",
                    "ak": LoginService.default.ak,
                    "network": 1,
                    "model": "iPhone8,2",
                    "ps": 30,
                    "ppi": 401,
                    "idfa": "8039a09a9a56f2c35251b956c2"]
        case let .audioList(id, page):
            return ["albumId": id,
                    "page": page,
                    "pageSize": 30,
                    "__se_token": "2877865c-4e0a-4a1d-8a01-d531b2c6b659",
                    "__se_time": Date().timeStamp(),
                    "__se_signature": "925ed972f47fd07bdc166c322f281aea"]
        case let .audio(pid, id):
            return ["channelId": pid,
                    "programId": id,
                    "userId": LoginService.default.userId,
                    "__se_token": "2877865c-4e0a-4a1d-8a01-d531b2c6b659",
                    "__se_time": Date().timeStamp(),
                    "__se_signature": "925ed972f47fd07bdc166c322f281aea"]
        }
    }
}
